<?php

declare(strict_types=1);

namespace App\Model;


/**
 * @property int $id ID
 * @property int $userid 用户ID
 * @property int $room_id 房间ID
 * @property int $seasion_id 直播场次ID 
 * @property int $gift_id 礼物ID
 * @property string $gift_name 礼物名称
 * @property int $gift_coins 礼物金币
 * @property string $payment 支付方式
 * @property int $quantity 数量
 * @property int $amount 总金额
 * @property int $idx_date 索引-日期
 * @property int $add_time 赠送时间
 * @property-read null|User $user 
 * @property-read null|Live $live 
 */
class LiveSessionGift extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'live_session_gift';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'userid', 'room_id', 'seasion_id', 'gift_id', 'gift_name', 'gift_coins', 'payment', 'quantity', 'amount', 'idx_date', 'add_time'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'userid' => 'integer', 'room_id' => 'integer', 'seasion_id' => 'integer', 'gift_id' => 'integer', 'gift_coins' => 'integer', 'quantity' => 'integer', 'amount' => 'integer', 'idx_date' => 'integer', 'add_time' => 'integer'];

    public function user(){
        return $this->hasOne(User::class, 'id', 'userid')->select(['id', 'username', 'nickname', 'avatar', 'role_id']);
    }

    public function live(){
        return $this->hasOne(Live::class, 'room_id', 'room_id')->select(['room_id', 'room_name']);
    }
}
